//
//  DLTDetailTableViewController.m
//  CaiPiao
//
//  Created by apple on 2018/5/18.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "DLTDetailTableViewController.h"

@interface DLTDetailTableViewController ()

@property(nonatomic,retain)NSDictionary* detailDic;

@property (weak, nonatomic) IBOutlet UILabel *SaleMoneyLabel;
@property (weak, nonatomic) IBOutlet UILabel *TotalMoneyLabel;
@property (weak, nonatomic) IBOutlet UILabel *IssueNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *EndTimeLabel;
@property (weak, nonatomic) IBOutlet UIView *WinNumberBoxView;
@property (weak, nonatomic) IBOutlet UILabel *winCount_1;
@property (weak, nonatomic) IBOutlet UILabel *winCount_2;
@property (weak, nonatomic) IBOutlet UILabel *winCount_3;
@property (weak, nonatomic) IBOutlet UILabel *winCount_4;
@property (weak, nonatomic) IBOutlet UILabel *winCount_5;
@property (weak, nonatomic) IBOutlet UILabel *winCount_6;
@property (weak, nonatomic) IBOutlet UILabel *winCount_7;
@property (weak, nonatomic) IBOutlet UILabel *winCount_8;
@property (weak, nonatomic) IBOutlet UILabel *winCount_9;
@property (weak, nonatomic) IBOutlet UILabel *winCount_10;
@property (weak, nonatomic) IBOutlet UILabel *winCount_11;
@property (weak, nonatomic) IBOutlet UILabel *winCount_12;

@property (weak, nonatomic) IBOutlet UILabel *winMoney_1;
@property (weak, nonatomic) IBOutlet UILabel *winMoney_2;
@property (weak, nonatomic) IBOutlet UILabel *winMoney_3;
@property (weak, nonatomic) IBOutlet UILabel *winMoney_4;
@property (weak, nonatomic) IBOutlet UILabel *winMoney_5;
@property (weak, nonatomic) IBOutlet UILabel *winMoney_6;
@property (weak, nonatomic) IBOutlet UILabel *winMoney_7;
@property (weak, nonatomic) IBOutlet UILabel *winMoney_8;
@property (weak, nonatomic) IBOutlet UILabel *winMoney_9;
@property (weak, nonatomic) IBOutlet UILabel *winMoney_10;
@property (weak, nonatomic) IBOutlet UILabel *winMoney_11;
@property (weak, nonatomic) IBOutlet UILabel *winMoney_12;



@end

@implementation DLTDetailTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    
    self.title = [NSString stringWithFormat:@"%@开奖详情",[LotteryManager sharedManager].currentLotteryName];
    
    [EasyLodingView showLodingText:@"正在努力加载中..." config:^EasyLodingConfig *{
        return [EasyLodingConfig shared].setLodingType(LodingShowTypeIndicator);
    }];
    
    
    __weak typeof(self)weakSelf = self;
    [[LotteryManager sharedManager] getLotteryDetailWithissueID:[LotteryManager sharedManager].currentDetailID andActionID:@"601" andCallBack:^(BOOL load, NSDictionary *resObj) {
        if (load) {
            weakSelf.detailDic = resObj[@"data"];
            [weakSelf loadDetailAction];
        }
    }];
}

-(void)addNumberWith:(NSString*)winNumber{
    CGFloat ballWith = self.WinNumberBoxView.frame.size.width/7-10;
    CGFloat addSpacing = 10;
    NSArray* winNumberArray = [winNumber componentsSeparatedByString:@"+"];
    if ([winNumberArray count]>0) {
        NSArray* redArray;
        NSArray* blueArray;
        
        NSString* redString = [winNumberArray objectAtIndex:0];
        if ([redString rangeOfString:@","].location == NSNotFound) {
            redArray = [redString componentsSeparatedByString:@" "];
        }else{
            redArray = [redString componentsSeparatedByString:@","];
        }
        if ([winNumberArray count]>1) {
            NSString* blueString = [winNumberArray objectAtIndex:1];
            if ([blueString rangeOfString:@","].location == NSNotFound) {
                blueArray = [blueString componentsSeparatedByString:@" "];
            }else{
                blueArray = [blueString componentsSeparatedByString:@","];
            }
        }
        float spacingX = 0;
        for (int i=0; i<[redArray count]; i++) {
            UIView* numberView = [[UIView alloc] initWithFrame:CGRectMake(i*(ballWith+addSpacing), 10, ballWith, ballWith)];
            numberView.backgroundColor = [UIColor colorWithRed:(255.0/255.0) green:(90/255.0) blue:0 alpha:1];
            UILabel* numberLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, ballWith, ballWith)];
            numberLabel.font = [UIFont boldSystemFontOfSize:15];
            numberLabel.textColor = [UIColor whiteColor];
            numberLabel.textAlignment = NSTextAlignmentCenter;
            numberLabel.text = [redArray objectAtIndex:i];
            [numberView addSubview:numberLabel];
            numberView.layer.cornerRadius = ballWith*0.5;
            [self.WinNumberBoxView addSubview:numberView];
            spacingX+=(ballWith+addSpacing);
        }
        
        for (int i=0; i<[blueArray count]; i++) {
            UIView* numberView = [[UIView alloc] initWithFrame:CGRectMake(spacingX, 10, ballWith, ballWith)];
            numberView.backgroundColor = [UIColor colorWithRed:(69.0/255.0) green:(160/255.0) blue:(255.0/255.0) alpha:1];
            UILabel* numberLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, ballWith, ballWith)];
            numberLabel.font = [UIFont boldSystemFontOfSize:15];
            numberLabel.textColor = [UIColor whiteColor];
            numberLabel.textAlignment = NSTextAlignmentCenter;
            numberLabel.text = [blueArray objectAtIndex:i];
            [numberView addSubview:numberLabel];
            numberView.layer.cornerRadius = ballWith*0.5;
            [self.WinNumberBoxView addSubview:numberView];
            spacingX+=(ballWith+addSpacing);
        }
    }
}

-(void)loadDetailAction{
    [EasyLodingView hidenLoding];
    self.SaleMoneyLabel.text = self.detailDic[@"SaleMoney"];
    self.TotalMoneyLabel.text = self.detailDic[@"TotalMoney"];
    self.IssueNameLabel.text = self.detailDic[@"IssueName"];
    self.EndTimeLabel.text = [NSString stringWithFormat:@"开奖时间:%@",[self.detailDic[@"EndTime"] stringByReplacingOccurrencesOfString:@"/" withString:@"-"]];
    [self addNumberWith:self.detailDic[@"WinNumber"]];
    
    NSArray* itemArray = self.detailDic[@"item"];
    for (int i=0; i<[itemArray count]; i++) {
        NSDictionary* dic = itemArray[i];
        switch (i) {
            case 0:
                self.winCount_1.text = dic[@"winCount"];
                self.winMoney_1.text = dic[@"winMoney"];
                break;
            case 1:
                self.winCount_2.text = dic[@"winCount"];
                self.winMoney_2.text = dic[@"winMoney"];
                break;
            case 2:
                self.winCount_3.text = dic[@"winCount"];
                self.winMoney_3.text = dic[@"winMoney"];
                break;
            case 3:
                self.winCount_4.text = dic[@"winCount"];
                self.winMoney_4.text = dic[@"winMoney"];
                break;
            case 4:
                self.winCount_5.text = dic[@"winCount"];
                self.winMoney_5.text = dic[@"winMoney"];
                break;
            case 5:
                self.winCount_6.text = dic[@"winCount"];
                self.winMoney_6.text = dic[@"winMoney"];
                break;
            case 6:
                self.winCount_7.text = dic[@"winCount"];
                self.winMoney_7.text = dic[@"winMoney"];
                break;
            case 7:
                self.winCount_8.text = dic[@"winCount"];
                self.winMoney_8.text = dic[@"winMoney"];
                break;
            case 8:
                self.winCount_9.text = dic[@"winCount"];
                self.winMoney_9.text = dic[@"winMoney"];
                break;
            case 9:
                self.winCount_10.text = dic[@"winCount"];
                self.winMoney_10.text = dic[@"winMoney"];
                break;
            case 10:
                self.winCount_11.text = dic[@"winCount"];
                self.winMoney_11.text = dic[@"winMoney"];
                break;
            case 11:
                self.winCount_12.text = dic[@"winCount"];
                self.winMoney_12.text = dic[@"winMoney"];
                break;
            default:
                break;
        }
    }
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
//#warning Incomplete implementation, return the number of sections
//    return 0;
//}
//
//- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//#warning Incomplete implementation, return the number of rows
//    return 0;
//}

/*
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
    
    // Configure the cell...
    
    return cell;
}
*/

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
